/*
 * @Author: your name
 * @Date: 2021-09-22 09:47:48
 * @LastEditTime: 2021-09-23 09:35:15
 * @Description:
 */
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import eslintPlugin from 'vite-plugin-eslint'
import vueJsx from '@vitejs/plugin-vue-jsx'
import path from 'path'
import { svgBuilder } from './src/plugins/svg'

// https://vitejs.dev/config/
export default defineConfig({
  server: {
    proxy: {
      // 选项写法
      '/admin': {
        target: 'https://shop.fed.lagou.com/api',
        // 兼容基于名字的虚拟主机
        // a.com localhost:xxx
        // b.com localhost:xxx
        // HTTP 请求头部的 origin 字段
        // 我们在开发模式：默认 origin 是真实的 origin: localhost:3000
        // changeOrigin: true，代理服务会把 origin 修改为目标地址 http://jsonplaceholder.typicode.com
        changeOrigin: true

        // 路径重写
        // rewrite: (path) => path.replace(/^\/api/, '')
      }
    }
  },
  resolve: {
    alias: {
      '@': path.join(__dirname, 'src')
    }
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: '@import "@/styles/variables.scss";'
      }
    }
  },
  plugins: [
    vue(),
    eslintPlugin({
      // 配置项
      cache: false
    }),
    vueJsx({
      // options are passed on to @vue/babel-plugin-jsx
    }),
    svgBuilder('./src/icons/svg/')
  ]
})
